import requests
from bs4 import BeautifulSoup
import os
url = 'http://www.pxu.edu.cn/'

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'}
wb_data = requests.get(url, headers=headers)

def Saving(url,name):
    #root = r"D:\\"
    root = r'D:\\'
    path = root + name + '.HTML'
    try:
        if not os.path.exists(root):
            os.mkdir(root)
        if not os.path.exists(path):
            print(url)
            r = requests.get(url)
            print(r)
            with open(path, 'wb') as f:

                f.write(r.content)

                f.close()
                print("文件保存成功")
        else:
            print("文件已存在")
    except:
        print("爬虫失败")


Saving(url,'萍乡学院')
